package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.SystemMenu;
import cn.wolfcode.crm.mapper.SystemMenuMapper;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.ISystemMenuService;
import cn.wolfcode.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SystemMenuServiceImpl implements ISystemMenuService {
    @Autowired
    private SystemMenuMapper mapper;
    public void save(SystemMenu entity) {
        mapper.insert(entity);
    }

    public void update(SystemMenu entity) {
        mapper.updateByPrimaryKey(entity);
    }

    public void delete(Long id) {
        mapper.deleteByPrimaryKey(id);
    }

    public List<SystemMenu> list() {
        return mapper.selectAll();
    }

    public SystemMenu get(Long id) {
        return mapper.selectByPrimaryKey(id);
    }

    public PageResult query(QueryObject qo) {

        //1:查总条数
        int total = mapper.queryForCount(qo);

        if(total == 0){
            return new PageResult();
        }
        //2:查分页数据
        List<SystemMenu> rows = mapper.queryForList(qo);

        return new PageResult(total, rows);
    }

    public List<SystemMenu> queryRootMenu() {

        return  mapper.queryRootMenu();
    }

    public List<SystemMenu> queryChildrenMenu(Long parentId) {
        return mapper.queryChildrenMenu(parentId);
    }

}
